unit Con_Historico;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, Grids, DBGrids, StdCtrls, Buttons, ExtCtrls,
  Db, DBTables, TFlatButtonUnit;

type
  TFrmCon_Historico = class(TFrmConsulta)
    Label1: TLabel;
    edtNome: TEdit;
    dbgHistorico: TDBGrid;
    Label2: TLabel;
    p_ordem: TRadioGroup;
    btnGravar: TFlatButton;
    procedure BtnFecharClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure edtNomeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure p_ordemClick(Sender: TObject);
    procedure btnGravarClick(Sender: TObject);
    procedure dbgHistoricoDblClick(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Hist_Codigo: string;
  end;

var
  FrmCon_Historico: TFrmCon_Historico;
  xHist_Codigo: string;

implementation

uses dm, clsHistorico, Cad_Historico, menu;

var
  Historico: THistorico;
  tds: Tdatasource;
  tq: Tquery;

{$R *.DFM}

procedure TFrmCon_Historico.BtnFecharClick(Sender: TObject);
begin
  Hist_Codigo := tq.fieldbyname('Hist_Codigo').asstring;
  xHist_Codigo := tq.fieldbyname('Hist_Codigo').asstring;
  inherited;
end;

procedure TFrmCon_Historico.FormActivate(Sender: TObject);
begin
  inherited;
  if FileExists(caminho_personal + 'belquimica') then begin
    btnGravar.Visible := False;
  end;
  tq.databasename := dmint.db.databasename;
  tds.DataSet := tq;
  dbgHistorico.DataSource := tds;
  fazconsulta;
end;

procedure TFrmCon_Historico.edtNomeKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if key = 12 then FazConsulta;
end;

procedure TfrmCon_Historico.FazConsulta;
begin
  Historico.Consultar(edtnome.text, p_ordem.itemindex, tq);
end;

procedure TFrmCon_Historico.FormDestroy(Sender: TObject);
begin
  inherited;
  Historico.free;
  tds.free;
  tq.free;
end;

procedure TFrmCon_Historico.FormCreate(Sender: TObject);
begin
  inherited;
  Historico := THistorico.Create;
  tds := TDataSource.create(self);
  tq := Tquery.create(self);
end;

procedure TFrmCon_Historico.p_ordemClick(Sender: TObject);
begin
  inherited;
  FazConsulta;
end;

procedure TFrmCon_Historico.btnGravarClick(Sender: TObject);
var
  f1: TfrmCad_Historico;
begin
  inherited;
  f1 := TfrmCad_Historico.Create(Self);
  f1.btnC_Historico.Visible := False;
  f1.ShowModal;
  f1.Free;
  FazConsulta;
end;

procedure TFrmCon_Historico.dbgHistoricoDblClick(Sender: TObject);
begin
  inherited;
  BtnFecharClick(Sender);
end;

end.

